package com.lxmes.hr.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.hr.domain.NcAbnormalMoney;
import com.lxmes.hr.service.INcAbnormalMoneyService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 工资异动审批Controller
 *
 * @author ruoyi
 * @date 2023-02-17
 */
@RestController
@RequestMapping("/hr/abnormalMoney")
public class NcAbnormalMoneyController extends BaseController
{
    @Autowired
    private INcAbnormalMoneyService ncAbnormalMoneyService;

    /**
     * 查询工资异动审批列表
     */
    @PreAuthorize("@ss.hasPermi('hr:abnormalMoney:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcAbnormalMoney ncAbnormalMoney)
    {
        startPage();
        List<NcAbnormalMoney> list = ncAbnormalMoneyService.selectNcAbnormalMoneyList(ncAbnormalMoney);
        return getDataTable(list);
    }

    /**
     * 导出工资异动审批列表
     */
    @PreAuthorize("@ss.hasPermi('hr:abnormalMoney:export')")
    @Log(title = "工资异动审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcAbnormalMoney ncAbnormalMoney)
    {
        List<NcAbnormalMoney> list = ncAbnormalMoneyService.selectNcAbnormalMoneyList(ncAbnormalMoney);
        ExcelUtil<NcAbnormalMoney> util = new ExcelUtil<NcAbnormalMoney>(NcAbnormalMoney.class);
        util.exportExcel(response, list, "工资异动审批数据");
    }

    /**
     * 获取工资异动审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:abnormalMoney:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncAbnormalMoneyService.selectNcAbnormalMoneyById(id));
    }

    /**
     * 新增工资异动审批
     */
    @PreAuthorize("@ss.hasPermi('hr:abnormalMoney:add')")
    @Log(title = "工资异动审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcAbnormalMoney ncAbnormalMoney)
    {
        return toAjax(ncAbnormalMoneyService.insertNcAbnormalMoney(ncAbnormalMoney));
    }

    /**
     * 修改工资异动审批
     */
    @PreAuthorize("@ss.hasPermi('hr:abnormalMoney:edit')")
    @Log(title = "工资异动审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcAbnormalMoney ncAbnormalMoney)
    {
        return toAjax(ncAbnormalMoneyService.updateNcAbnormalMoney(ncAbnormalMoney));
    }

    /**
     * 删除工资异动审批
     */
    @PreAuthorize("@ss.hasPermi('hr:abnormalMoney:remove')")
    @Log(title = "工资异动审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncAbnormalMoneyService.deleteNcAbnormalMoneyByIds(ids));
    }

    /**
     * 导入工资异动审批
     */
    @Log(title = "工资异动审批", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcAbnormalMoney> util = new ExcelUtil<>(NcAbnormalMoney.class);
        List<NcAbnormalMoney> ncAbnormalMoneyList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncAbnormalMoneyService.imporIteminfo(ncAbnormalMoneyList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<NcAbnormalMoney> util = new ExcelUtil<>(NcAbnormalMoney.class);
        util.importTemplateExcel(response,"工资异动审批");
    }
}
